package com.xinziruo.richclient.util.filecommand.impl;

import java.io.File;

import org.apache.commons.io.FileUtils;

import com.xinziruo.richclient.util.ExceptionUtils;
import com.xinziruo.richclient.util.filecommand.FileCommand;

/**
 * 
 * 
 * @author loudyn.
 */
public class DeleteFileCommand implements FileCommand {
	private final File file;

	/**
	 * 
	 * @param fileName
	 */
	public DeleteFileCommand(final String fileName) {
		this(new File(fileName));
	}

	/**
	 * 
	 * @param file
	 */
	public DeleteFileCommand(final File file) {
		this.file = file;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.youboy.module.util.filecommand.FileCommand#execute()
	 */
	public void execute() {
		try {
			if (!file.exists())
				return;

			if (file.isFile()) {
				file.delete();
				return;
			}

			FileUtils.deleteDirectory(file);
		} catch (Exception e) {
			throw ExceptionUtils.toUnchecked(e);
		}
	}
}
